package board.animation.tranlations;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.ImageObserver;

import board.PointSpaceTranslator;
import board.grid.Space;
import board.animation.render.AnimatedOccupantRender;

public class CompoundAnimation<T> implements Translation<T> {
	private Translation<T> translation;
	private AnimatedOccupantRender<T> render;
	
	public CompoundAnimation() {}
	public CompoundAnimation(Translation<T> translation) {setTranslation(translation);}
	public CompoundAnimation(AnimatedOccupantRender<T> render) {setRender(render);}
	public CompoundAnimation(Translation<T> translation, AnimatedOccupantRender<T> render) {
		setTranslation(translation);
		setRender(render);
	}
	
	public void setTranslation(Translation<T> translation) {this.translation = translation;}
	public void setRender(AnimatedOccupantRender<T> render) {this.render = render;}
	
	public Translation<T> getTranslation() {return translation;}
	public AnimatedOccupantRender<T> getRender() {return render;}

	@Override
	public void setOccupant(T occupant) {
		translation.setOccupant(occupant);
		render.setOccupant(occupant);}
	@Override
	public T getOccupant() {
		T occupant = translation.getOccupant();
		if(occupant == render.getOccupant())
			return occupant;
		else
			throw new IllegalStateException("The occupants of the compounding animations do not match.  ");
	}
	@Override
	public boolean isComplete() {return translation.isComplete() && render.isComplete();}
	@Override
	public void next() {
		translation.next();
		render.next();
	}
	@Override
	public void draw(Image render, Graphics2D area, ImageObserver i, PointSpaceTranslator t)
		{translation.draw(this.render.getNewImage(render, i), area, i, t);}

	@Override
	public void setTranslation(Space start, Space end, int speed)
		{throw new IllegalStateException("The translation on CompoundAnimation<T> should be set using the unserlying Translation<T>.  ");}
}
